import { SelectionModel, TextModel } from "../models"
import { md2html } from "../parser"
import { RenderView } from "./SourceView"

export class SourcePreview extends RenderView {
  public previewElement?: HTMLElement
  constructor(
    textModel_: TextModel,
    selectionModel_: SelectionModel,
    viewContainer_: HTMLElement,
  ) {
    super(textModel_, selectionModel_, viewContainer_)
    const previewElement = document.getElementById("container-preview")
    if (previewElement) {
      previewElement.style.display = "block"
      this.previewElement = previewElement
    }
  }

  render() {
    super.render()
    if (this.previewElement)
      this.previewElement.innerHTML = md2html(this.textModel_.getSpacers())
  }
}
